<script type="text/javascript">
	//List Configuration
	$j("#list_familypatient").jqGrid({
		url:'familybackground/list/<?php echo $parameters["id_patient"];?>',
		datatype:'json',
		mtype:'POST',
		colNames:['Familiar', 'Cardíaco', 'Diabéticos','Colesterol', 'Hipertensión', 'Paciente'],
		colModel:[
		          {
			          name:'family_id',
			          index:'family_id', 
			          width:30, 
			          editable: true,
			          edittype: 'select',
			          editoptions: {
			          	value:{
			          		<?php
			          		 $relatives = $parameters["relatives"];				          			 
					  		 $count = count($relatives);
					  		 for ($i = 0; $i < $count; $i++){
					  		 	echo $relatives[$i]->id.":'".$relatives[$i]->family_name."'";
					  		 	if (($i+1) < $count) echo ",";
					  		 	else echo "";
					  		 }
						    ?>
			          	}
			          }
			      },
			      {
			          name:'background_cardiac', 
			          index:'background_cardiac', 
			          width:10,
			          editable: true,
			          edittype: 'checkbox',
			          formatter: 'checkbox',
			          editoptions: {value: "1:0"},
			          align:"center"
			      },
			      {
			          name:'background_cholesterol', 
			          index:'background_cholesterol', 
			          width:10, 
			          editable: true,
			          edittype: 'checkbox',
			          formatter: 'checkbox',
			          editoptions: {value: "1:0"},
			          align:"center"
		          },
			      {
			          name:'background_diabetic', 
			          index:'background_diabetic', 
			          width:10, 
			          editable: true,
			          edittype: 'checkbox',
			          formatter: 'checkbox',
			          editoptions: {value: "1:0"},
			          align:"center"
			      },
			      {
			          name:'background_hypertension', 
			          index:'background_hypertension', 
			          width:10, 
			          editable: true,
			          edittype: 'checkbox',
			          formatter: 'checkbox',
			          editoptions: {value: "1:0"},
			          align:"center"
			      },
			      {
				      name: 'patient_id',
				      index: 'patient_id',
				      edittype: 'text',
				      editoptions: {value: <?php echo $parameters["id_patient"];?>},
				      width: 10,
				      editable: true,
				      hidden: true
				   }
		],
		pager:'#gridpager_familypatient',
		loadtext:'Cargando Antecedentes Familiares ...',
		rowNum:10,
		rowList:[10],
		sortname:'family_id',
		sortorder:'asc',
		autowidth:true,
		viewrecords:true,
		onSelectRow:function(id){},
		editurl:'familybackground/save/<?php echo $parameters["id_patient"];?>',
		scrollOffset:0
	});

	$j("#list_familypatient").setGridWidth("650",true);
	$j("#list_familypatient").setGridHeight(220);
	
	//Form editing
	$j("#list_familypatient").jqGrid('navGrid','#gridpager_familypatient',
			{
				edit:true,
				add:true,
				del:true,
				search:true
			},
			{
				closeAfterEdit:true,
				editCaption: "Modificar Antecedente Familiar"
			},
			{
				closeAfterAdd:true,
				addCaption: "Nuevo Antecedente Familiar"
			},
			{
				msg: "¿Desea eliminar el antecedente familiar seleccionado?",
				caption: "Eliminar Antecedente Familiar",
				width:350
			}
			);
</script>
